﻿(function($){
	var int2ChineseDict = { 
		'0' : '零', '1' : '一',
		'2' : '二', '3' : '三',
		'4' : '四', '5' : '五',
		'6' : '六', '7' : '七',
		'8' : '八', '9' : '九',
		'10' : '十', '100' : '百',
		'1000' : '千', '10000' : '万',
		'100000000' : '亿'
	};
	/**
	 * INPUT: number or string of number
	 * OUTPUT: Chinese version of the number
	 */
	var integer2Chinese = function(number){
		// just from 0 to 9 for now
		var num = parseInt(number);
		var result = '';
		var hundredMillion = Math.floor(num / 100000000);
		if(hundredMillion > 0){
			var hundredMillionStr = integer2Chinese(hundredMillion);
			result = result + hundredMillionStr + int2ChineseDict['100000000']; // ×××亿
		}
		num %= 100000000; 
		var tenThousand = Math.floor(num / 10000);
		if(tenThousand > 0){
			var tenThousandStr = integer2Chinese(tenThousand);
			result = result + tenThousandStr + int2ChineseDict['10000']; // ×××万
		}
		num %= 10000;
		var thousand = Math.floor(num / 1000);
		if(thousand > 0){
			var thousandStr = String(thousand);
			result = result + int2ChineseDict[thousandStr] + int2ChineseDict['1000']; // ×××千
		}
		num %= 1000;
		var hundred = Math.floor(num / 100);
		if(hundred > 0){
			var hundredStr = String(hundred);
			result = result + int2ChineseDict[hundredStr] + int2ChineseDict['100']; // ×××百
		}
		num %= 100;
		var ten = Math.floor(num / 10);
		if(ten > 0){
			var tenStr = String(ten);
			result = result + int2ChineseDict[tenStr] + int2ChineseDict['10']; // ×××十
		}
		num %= 10;
		if(num > 0 && num < 10 ){
			var numStr = String(num);
			result += int2ChineseDict[numStr];
		}
		return result;
	};
	
	// TODO: Need More Polishing
	var titleStyles = {
		'chapterTitle' : {
			'prefix' :
				function(pre){
					if(pre){
					}
					else {
						return '第';
					}
				},
			'postfix' :
				function(post){
					if(post){
					}
					else {
						return '章';
					}
				},
			'index' : 
				function(num){}
		},
	};
	
	var addIDsToTitles = function(){
		
	};
	
	/*
	Formating: like XML 
	缺点：写作时，结构不清晰
	<div>
		<div class="title">
		</div>
		<div class="content">
			<div class="title">
			</div>
			<div class="content">
				<div class="title">
				</div>
				<div class="content">
					<div class="title">
					</div>
					<div class="content">
					</div>
					
					<div class="title">
					</div>
					<div class="content">
					</div>
				</div>
			</div>
			
			<div class="title">
			</div>
			<div class="content">
			</div>
		</div>
	</div>
	*/
}(jQuery));

